﻿@{
	PageData["Title"] = "Create a new Feature";
    
    WebSecurity.RequireAuthenticatedUser();
    if (!Roles.IsUserInRole("admin")) {
    	Response.Redirect("~");
    }
    
	var name = "";	
	var description = "";	
    var errorMessage = "";
    
    if(IsPost) {        
        name = Request["name"];        
        description = Request["description"];
       
        if (name.IsEmpty()) {
            errorMessage = "Name cannot be empty.";
        }
               
        //If no errors in validation, continue with registration
        if (errorMessage.IsEmpty()) {
            try {
                Freemium.CreateFeature(name, description);                
                Response.Redirect("~/Freemium/Admin");
            } catch (Exception ex) {
                Response.Write(ex.ToString());
                Response.Write(string.Format("{0},{1}",name,description));                    
            }        
        }   
    }
}

@if (!errorMessage.IsEmpty()) {
<div class="error">
    @errorMessage
</div>
}
<h1>Feature Creation</h1>
Use the form below to create a new Freemium Feature.<br/>
<div>
    <form id="validateForm" method="post" action="">
	    <fieldset>
			<legend>Create Feature</legend>
			<div class="freemiumLabel">
				<label class="" for="name">Name</label>
			</div>
			<div class="freemiumInput">
				<input id="name" name="name" type="text" maxlength="128" value="@name" />
			</div>
			<div class="freemiumLabel">
				<label for="description">Description</label>
			</div>
			<div class="freemiumInput">
				<input id="description" name="description" type="text" maxlength="1000" value="@description" />
			</div>			

			<div class="freemiumSubmitGroup">
				<input type="submit" value="Create" />
				<input type="reset" value="Reset" />
				<input type="button" value="Cancel" name="action" onclick="javascript:window.location='@Href("~/Freemium/Admin")'" />
			</div>
        </fieldset>                
    </form>
</div>